
public class AnimatedGuiElement extends GuiElement{

	final float DAMPING = (float)0.5;
	final float ATTRACTION = (float)0.15;

	float velX, velY;
	float accel;
	float forceX, forceY;
	float mass = 1;

	float damping = DAMPING;
	float attraction = ATTRACTION;
	boolean targeting;
	float targetX, targetY;


	public AnimatedGuiElement() {}

	public AnimatedGuiElement(float xValue, float yValue) {
		x = xValue;
		y = yValue;
	}

	void set(float v, float u) {
		x = v;
		y = u;
	}


	void update(){
		if (targeting) {
			forceX += attraction * (targetX - x);      
		}

		accel = forceX / mass;
		velX = (velX + accel) * damping;
		x += velX;
		
		if (targeting) {
			forceY += attraction * (targetY - y);      
		}

		accel = forceY / mass;
		velY = (velY + accel) * damping;
		y += velY;

		forceX = 0;	
		forceY = 0;
				
	}


	void target(float x, float y) {
		targeting = true;
		targetX = x;
		targetY = y;
	}


	void noTarget() {
		targeting = false;
	}

}
